/**
 * @file app\protocol\mobus\inc\protocol_mobus_def.h
 *
 * Copyright (C) 2023
 *
 * protocol_mobus_def.h is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 *
 * @author HinsShum hinsshum@qq.com
 *
 * @encoding utf-8
 */
#ifndef __PROTOCOL_MOBUS_DEF_H
#define __PROTOCOL_MOBUS_DEF_H

#ifdef __cplusplus
extern "C" {
#endif

    /*---------- includes ----------*/
#include <stdbool.h>
#include <stddef.h>
#include <stdint.h>

/*---------- macro ----------*/
/*---------- type define ----------*/
/* protocol mobus frame type */
    typedef enum {
        MOBUS_FRAME_TYPE_BROADCAST = 0x00,
        MOBUS_FRAME_TYPE_QUERY_STATUS = 0x01,
        MOBUS_FRAME_TYPE_LOGIN = 0x02,
        MOBUS_FRAME_TYPE_ACK = 0x03,
        MOBUS_FRAME_TYPE_COMMAND = 0x04,
        MOBUS_FRAME_TYPE_UPLOAD_DATA = 0x04,
        MOBUS_FRAME_TYPE_CONFIG_CHANNEL = 0x05,
        MOBUS_FRAME_TYPE_CONFIG_INFRARED = 0x06,
        MOBUS_FRAME_TYPE_CONFIG_DEVICE = 0x08,
        MOBUS_FRAME_TYPE_GATEWAY_ATTRIBUTE = 0x09,
        MOBUS_FRAME_TYPE_RESTORE = 0x0A,
        MOBUS_FRAME_TYPE_QUERY_INFORMATION = 0x0C,
        MOBUS_FRAME_TYPE_QUERY_PARAMETERS = 0x20,
        MOBUS_FRAME_TYPE_REQUEST_DATA = 0x21,
        MOBUS_FRAME_TYPE_REQUEST_UPGRADE = 0x22,
        MOBUS_FRAME_TYPE_CONFIG_PARAMETERS = 0x23,
        MOBUS_FRAME_TYPE_UPLOAD_SENSOR_DATA = 0x24,
        MOBUS_FRAME_TYPE_UPLOAD_ALARM_DATA = 0x25,
        MOBUS_FRAME_TYPE_DELETE_INFRARED = 0x26,
        MOBUS_FRAME_TYPE_UPLOAD_STATUS = 0x27,
        MOBUS_FRAME_TYPE_CAPTURE = 0x29,
        MOBUS_FRAME_TYPE_GROUP = 0x2D,
        MOBUS_FRAME_TYPE_CONFIG_GROUP_ADDR = 0x2E,
        MOBUS_FRAME_TYPE_UPLOAD_GROUP_ADDR = 0x2F,
        MOBUS_FRAME_TYPE_REPORT_ERROR = 0x33,
        MOBUS_FRAME_TYPE_OCCUPIED = 0x3B,
        MOBUS_FRAME_TYPE_UNOCCUPIED = 0x3C,
        MOBUS_FRAME_TYPE_UPLOAD_LOG = 0x3F,
        MOBUS_FRAME_TYPE_QUERY_LOG = 0x40,
        MOBUS_FRAME_TYPE_UPLOAD_AUTHINFO = 0x46,
        MOBUS_FRAME_TYPE_SET_AUTHINFO = 0x47,
        MOBUS_FRAME_TYPE_FACTORY_TEST = 0x52,
    } mobus_frame_type_t;

    /* protocol mobus ack result
     */
    typedef enum {
        MOBUS_ACK_OK = 0x00,
        MOBUS_ACK_SYNC = 0xF0,
        MOBUS_ACK_DATA_ERR = 0xF1,
        MOBUS_ACK_FULL_DATA = 0xF2,
        MOBUS_ACK_SETUP_ERR = 0xF3
    } mobus_ack_result_t;

    /* protocol mobus device type
     */
    typedef enum {
        /* board type */
        MOBUS_DEVICE_TYPE_LSKED = 0x7B36,
        MOBUS_DEVICE_TYPE_RUEN = 0x7936,
        MOBUS_DEVICE_TYPE_RUEN_WITH_SLIDER = 0x7935,
        /* relay type */
        MOBUS_DEVICE_TYPE_NOMAL_LIGHT = 0x0100,
        MOBUS_DEVICE_TYPE_WATER_HEATER = 0xD410,
        MOBUS_DEVICE_TYPE_ELECTRIC_COOKER = 0xD510,
        MOBUS_DEVICE_TYPE_RANGE_HOOD = 0xD610,
        MOBUS_DEVICE_TYPE_WASHING_MACHINE = 0xD710,
        MOBUS_DEVICE_TYPE_ICEBOX = 0xD810,
        MOBUS_DEVICE_TYPE_ELECTRONIC_TOILET = 0xD910,
        MOBUS_DEVICE_TYPE_FISH_TANK = 0xDA10,
        /* unknown */
        MOBUS_DEVICE_TYPE_UNKNOWN = 0xFFFF
    } mobus_device_type_t;

    typedef enum {
        MOBUS_CMD_NONE = 0,
        MOBUS_BROCAST_CMD_QUERY_STATUS = 0x01,
        MOBUS_BROCAST_CMD_QUERY_ONLINE = 0x02,
        MOBUS_RESTORE_CMD_REQUEST = 0x01,
        MOBUS_RESTORE_CMD_CONFIRM = 0x02,
        MOBUS_GROUP_CONFIG_CMD_ADD = 0x01,
        MOBUS_GROUP_CONFIG_CMD_MODIFY = 0x02,
        MOBUS_GROUP_CONFIG_CMD_DEL = 0x03,
        MOBUS_GROUP_CONFIG_CMD_READ_NUMS = 0x04,
        MOBUS_GROUP_CONFIG_CMD_READ_CONTENT = 0x05,
        MOBUS_CMD_QUERY_STATUS = 0x07,
        MOBUS_CMD_QUERY_ONLINE = 0x08,
        MOBUS_CMD_QUERY_INFO = 0x09
    } mobus_cmd_t;

    typedef enum {
        MOBUS_FACTORY_TEST_CMD_BEGIN = 0xF1,
        MOBUS_FACTORY_TEST_CMD_REPORT_RESULT = 0xF2,
        MOBUS_FACTORY_TEST_CMD_REPORT_DATA = 0xF8,
    } mobus_factory_test_cmd_t;

    /*---------- variable prototype ----------*/
    /*---------- function prototype ----------*/

#ifdef __cplusplus
}
#endif
#endif /* __PROTOCOL_MOBUS_DEF_H */
